package com.gdth.bank.presenter;

import com.gdth.bank.BankApplication;
import com.gdth.bank.bean.AppDevBean;
import com.gdth.bank.model.CjkhjlModel;
import com.gdth.bank.model.UnbindAppModel;
import com.gdth.bank.view.CjkhjlView;
import com.gdth.bank.view.UnbindAppView;
import com.gdth.widget.dialog.BaseToast;
import com.google.gson.Gson;

import rx.Subscriber;
import rx.schedulers.Schedulers;

/** 
 * @author  Arvin: 
 * @version 2016年5月25日 下午10:40:57 
 * 
 */
public class UnbindAppPresenter {
	private UnbindAppView unbindAppView;
	private UnbindAppModel unbindAppModel;

	public UnbindAppPresenter(UnbindAppView unbindAppView){
		this.unbindAppView = unbindAppView;
		unbindAppModel = new UnbindAppModel();
	}
	/**
	 * 获取app 列表
	 * @param
	 */
	public void getAppdevList(){
			unbindAppModel.getAppList()
					.subscribeOn(Schedulers.io())
					.unsubscribeOn(Schedulers.io())
					.observeOn(Schedulers.io())
					.subscribe(new Subscriber<String>(){

						@Override
						public void onCompleted() {
							// TODO Auto-generated method stub
						}

						@Override
						public void onError(Throwable arg0) {
							// TODO Auto-generated method stub
							BaseToast.getInstance().ShowCenterToast(BankApplication.mInstance.getBaseContext(), "获取参数失败："+arg0.getMessage());
						}

						@Override
						public void onNext(String arg0) {
							// TODO Auto-generated method stub
							Gson mGson = new Gson();
							AppDevBean  bean= mGson.fromJson(arg0, AppDevBean.class);
							unbindAppView.saveSuccess(bean.getYhList());
						}
					});
	}

	public void delAppDev(String sfz){
		String content = "{\"sfz\":\""+sfz+"\"}";;
		unbindAppModel.delAppDev(content)
				.subscribeOn(Schedulers.io())
				.unsubscribeOn(Schedulers.io())
				.observeOn(Schedulers.io())
				.subscribe(new Subscriber<String>(){

					@Override
					public void onCompleted() {
						// TODO Auto-generated method stub
					}

					@Override
					public void onError(Throwable arg0) {
						// TODO Auto-generated method stub
						BaseToast.getInstance().ShowCenterToast(BankApplication.mInstance.getBaseContext(), "获取参数失败："+arg0.getMessage());
					}

					@Override
					public void onNext(String arg0) {
						// TODO Auto-generated method stub

						unbindAppView.updateView(arg0);
					}
				});
	}
}
